package com.by.pojo;

/**
 * @version 1.0
 * @Author 彭彦彬
 * @Date 2025/4/12 15:00
 * @注释
 */
public class Burger {
    private String bread;   // 面包类型
    private String patty;   // 肉饼类型
    private String sauce;   // 酱料类型
    private boolean cheese; // 是否加芝士
    private boolean lettuce;// 是否加生菜

    // 私有构造函数，只能通过 Builder 构建
    private Burger(Builder builder) {
        this.bread = builder.bread;
        this.patty = builder.patty;
        this.sauce = builder.sauce;
        this.cheese = builder.cheese;
        this.lettuce = builder.lettuce;
    }

    // 显示汉堡配置
    public void showBurger() {
        System.out.println("Your burger is ready!");
        System.out.println("- Bread: " + bread);
        System.out.println("- Patty: " + patty);
        System.out.println("- Sauce: " + (sauce != null ? sauce : "No sauce"));
        System.out.println("- Cheese: " + (cheese ? "Yes" : "No"));
        System.out.println("- Lettuce: " + (lettuce ? "Yes" : "No"));
    }

    // 静态内部类 Builder
    public static class Builder {
        // 必需的属性
        private String bread;
        private String patty;

        // 可选的属性
        private String sauce;
        private boolean cheese;
        private boolean lettuce;

        // 设置必需的属性
        public Builder(String bread, String patty) {
            this.bread = bread;
            this.patty = patty;
        }

        // 设置可选属性
        public Builder setSauce(String sauce) {
            this.sauce = sauce;
            return this;
        }

        public Builder addCheese(boolean cheese) {
            this.cheese = cheese;
            return this;
        }

        public Builder addLettuce(boolean lettuce) {
            this.lettuce = lettuce;
            return this;
        }

        // 构建最终的 Burger 对象
        public Burger build() {
            return new Burger(this);
        }
    }
}